using System;
using System.Collections.Generic;
using System.Text;

using MediaPortal.GUI.Library;
using MediaPortal.Dialogs;
using MediaPortal.Util;
using MediaPortal.Localisation;
using MediaPortal.Configuration;
using MediaPortal.Player;
using MediaPortal.Playlists;

using YahooMusicEngine;
using YahooMusicEngine.OnlineDataProvider;
using YahooMusicEngine.Services;
using YahooMusicEngine.Entities;

namespace YahooMusicPlugin
{
  class GUIYahooMusic_old : GUIWindow, ISetupForm
  {
    #region variebiles
    ServiceProvider provider = new ServiceProvider();
    CategoryTreeService catserv = new CategoryTreeService();
    CategoryEntity lastItems = new CategoryEntity();
    VideosForACategoryService videolist = new VideosForACategoryService();

    #endregion

    #region skin connection
    [SkinControlAttribute(50)]
    protected GUIFacadeControl listControl = null;
    [SkinControlAttribute(2)]
    protected GUISortButtonControl sortButton = null;
    [SkinControlAttribute(4)]
    protected GUIButtonControl homeButton = null;
    [SkinControlAttribute(3)]
    protected GUIButtonControl btnSwitchView = null;
    [SkinControlAttribute(5)]
    protected GUIButtonControl searchButton = null;
    [SkinControlAttribute(6)]
    protected GUIButtonControl presetsButton = null;
    [SkinControlAttribute(51)]
    protected GUIImage logoImage = null;
    #endregion

    #region ISetupForm Members

    public string PluginName()
    {
      return "Yahoo Music";
    }
    // returns plugin description
    public string Description()
    {
      return "Plugin for expose the Yahoo Music contents";
    }
    // returns author
    public string Author()
    {
      return "Dukus";
    }
    // shows the setup dialog
    public void ShowPlugin()
    {
      SetupForm setup = new SetupForm();
      setup.ShowDialog();
    }
    // enable / disable
    public bool CanEnable()
    {
      return true;
    }
    // returns the unique id again
    public int GetWindowId()
    {
      return 27050;
    }
    // default enable?
    public bool DefaultEnabled()
    {
      return true;
    }
    // has setup gui?
    public bool HasSetup()
    {
      return true;
    }
    // home button
    public bool GetHome(out string strButtonText, out string strButtonImage,
      out string strButtonImageFocus, out string strPictureImage)
    {
      // set the values for the buttom
      strButtonText = "Yahoo Music";

      // no image or picture
      strButtonImage = String.Empty;
      strButtonImageFocus = String.Empty;
      strPictureImage = String.Empty;

      return true;
    }
    #endregion

    public GUIYahooMusic_old()
    {

    }
    // init the skin
    public override bool Init()
    {
      Log.Debug("Init");
      // show the skin
      //provider.AppId = "BL9ngKjV34FbSKKUNcIx4Xg3Cv5aDALpWY1Fjob5DS_q5eWnaohBW_0X5gRROYS5";
      return Load(GUIGraphicsContext.Skin + @"\yahoomusicmain.xml");
    }

         //do the init before page load
    protected override void OnPageLoad()
    {
      base.OnPageLoad();
      //Log.Debug("OnPageLoad");
      //provider.GetData(catserv);
      //UpdateListing();
      //Log.Debug("OnPageLoad done");
    }

    //protected override void OnPageDestroy(int new_windowId)
    //{
    //  //oldSelection = listControl.SelectedItem;
    //  base.OnPageDestroy(new_windowId);
    //}
    
    //protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType)
    //{

    //  base.OnClicked(controlId, control, actionType);
    //}

    //public override void OnAction(Action action)
    //{
    //  switch (action.wID)
    //  {
    //    default:
    //      base.OnAction(action);
    //      break;
    //  }
    //}

    public void UpdateListing()
    {
      GUIControl.ClearControl(GetID, listControl.GetID);
      addCategories(catserv.Items);
      addVideos(videolist.Items);
    }

    void addCategories(List<CategoryEntity> cats)
    {
      foreach (CategoryEntity cat in cats)
      {
        GUIListItem item = new GUIListItem();
        // and add station name & bitrate
        item.Label = cat.Name;
        item.Label2 = "";
        item.IsFolder = true;
        item.IconImage = "defaultFolderNF.png";
        item.MusicTag = cat;
        listControl.Add(item);
      }
    }

    void addVideos(List<VideoResponse> vids)
    {
      foreach (VideoResponse vi in vids)
      {
        GUIListItem item = new GUIListItem();
        // and add station name & bitrate
        item.Label = vi.Video.Title;
        item.Label2 = "";
        item.IsFolder = false;
        item.IconImage = "defaultFolderBack.png";
        item.MusicTag = vi;
        listControl.Add(item);
      }
    }

  }
}
